<html>
<head>
<meta charset="UTF-8">
<title>KBEngine - KBEngine bots</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>KBEngine module</h1>
This <a href="KBEngine.html">KBEngine</a> module provides the parts of the 
logical script layer access to <a href="../Classes/Entity.html">Entity</a>, 
as well as the data of other clients in the current process, and so on.
<h2><a href="#" onClick="obj=document.getElementById( 'classes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Classes</a></h2>
<table id="classes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="class_list"><a href="../Classes/Entity.html" class="class_list" >Entity</a></span>
</td></tr>

<tr><td>
<span class="class_list"><a href="../Classes/PyClientApp.html" class="class_list" >PyClientApp</a></span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member functions</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#addBots" class="function_list" >addBots</a>( reqCreateAndLoginTotalCount, reqCreateAndLoginTickCount=0, reqCreateAndLoginTickTime=0 ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#callback" class="function_list" >callback</a>( initialOffset, callbackObj ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#cancelCallback" class="function_list" >cancelCallback</a>( id ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#genUUID64" class="function_list" >genUUID64</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcher" class="function_list" >getWatcher</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcherDir" class="function_list" >getWatcherDir</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#scriptLogType" class="function_list" >scriptLogType</a>( logType ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#urlopen" class="function_list" >urlopen</a>( url, callback, postData, headers ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callbacks</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
<span class="function_list">def <a href="#onInit" class="function_list" >onInit</a>( isReload ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onFinish" class="function_list" >onFinish</a>( ):</span>
</td></tr>
</table>

<h2><a href="#" onClick="obj=document.getElementById( 'attributes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Attributes</a></h2>
<table id="attributes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><a href="#bots" class="attribute_list" >bots</a></td><td>&nbsp; <a href="../Classes/PyClientApp.html">bots</a>

<tr valign=top><td><a href="#component" class="attribute_list" >component</a></td><td>&nbsp; Read-only <a href="STRING.html">string</a></td></tr>

</td></tr>

</table>

<hr>
<h2>Member functions documentation</h2>

<a name="addBots"></a><p class="function_definition">
<span class="function_definition">def addBots( <i>reqCreateAndLoginTotalCount, reqCreateAndLoginTickCount=0, reqCreateAndLoginTickTime=0</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Add a bot to the server.
<br><br>
Example:

<pre><pre># Here is an example of using addBots
        import <a href="../Modules/KBEngine.html">KBEngine</a>
&nbsp;
        # Add 5 robots to the server at one time (instantaneously).
        KBEngine.addBots( 5 )
&nbsp;
        # Add a total of 1000 robots to the server, 5 at a time, at an interval of 10 seconds.
        KBEngine.addBots( 1000, 5, 10 )
</pre>
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>reqCreateAndLoginTotalCount</i></span></td><td><span class="function_parameter_description">
integer, integer, the total number of bots to add to the server.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>reqCreateAndLoginTickCount</i></span></td><td><span class="function_parameter_description">
integer, the number of bots added to the server each interval
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>reqCreateAndLoginTickTime</i></span></td><td><span class="function_parameter_description">
integer, the interval of time (in seconds) between adding bots.
</span></td></tr>

</table>
</p>




<a name="callback"></a><p class="function_definition">
<span class="function_definition">def callback( <i>initialOffset, callbackObj</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a callback, on the callbackObj function, which will be executed 
once after "initialOffset" seconds.
<br><br>
Example:

<pre><pre># Here is an example of using callback
        import <a href="../Modules/KBEngine.html">KBEngine</a>
&nbsp;
        # Add a timer and execute it after 1 second
        KBEngine.callback( 1, onCallbackfun )
&nbsp;
    def onCallbackfun( ):
        print "onCallbackfun called"
	</pre>
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>initialOffset</i></span></td><td><span class="function_parameter_description">
float, time, in seconds, to wait before triggering the callback.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callbackObj</i></span></td><td><span class="function_parameter_description">
function, the specified callback function object.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>integer, this function returns the internal id of the callback. 
This id can be used with <a href="#cancelCallback">cancelCallback</a> to 
remove the callback.
</td></tr>
</table>
</p>



<a name="cancelCallback"></a><p class="function_definition">
<span class="function_definition">def cancelCallback( <i>id</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is used to remove a registered but not yet triggered callback. 
The removed callback will not be executed. If this function is passed an 
invalid id (for example, timer was removed), an error will be generated.
<br><br>
A use case is in the KBEngine.<a href="#callback">callback</a> example.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">
integer, specifies the callback id to remove.
</span></td></tr>

</table>
</p>



<a name="genUUID64"></a><p class="function_definition">
<span class="function_definition">def genUUID64( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function generates a 64-bit unique ID.<br>
Note: This function is dependent on the startup argument 'gus' of the 
Cellapps service process. Please set the startup arguments to be unique. <br>
In addition, if gus exceeds 65535, the function can only remain unique on 
the current process.
<br>
<br>
Usage:<br>
Unique item IDs are generated on multiple service processes and do not 
conflict when combined.<br>
A room ID is generated on multiple service process and no uniqueness 
verification is required.<br>
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
A 64-bit integer.
</td></tr>
</table>
</p>



<a name="getWatcher"></a><p class="function_definition">
<span class="function_definition">def getWatcher( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Gets the value of a watch variable from the KBEngine debug system.
<br>
<br>
Example: In the Python console of baseapp1 enter:<br>
>>>KBEngine.getWatcher("/root/stats/runningTime")
<br>
12673648533
<br>
<br>
>>>KBEngine.getWatcher("/root/scripts/players")
<br>
32133
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path of the variable including the variable name 
(can be viewed on the GUIConsole watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The value of the variable.
</td></tr>
</table>
</p>



<a name="getWatcherDir"></a><p class="function_definition">
<span class="function_definition">def getWatcherDir( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get a list of elements (directories, variable names) under the watch 
directory from the KBEngine debugging system.
<br>
<br>
Example: In the Python console of baseapp1 enter::<br>
>>>KBEngine.getWatcher("/root")
<br>
('stats', 'objectPools', 'network', 'syspaths', 'ThreadPool', 'cprofiles', 'scripts', 'numProxices', 'componentID', 'componentType', 'uid', 'numClients', 'globalOrder', 'username', 'load', 'gametime', 'entitiesSize', 'groupOrder')
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path of the variable including the variable name 
(can be viewed on the GUIConsole watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
A list of elements in the directory (directories, variable names).
</td></tr>
</table>
</p>



<a name="scriptLogType"></a><p class="function_definition">
<span class="function_definition">def scriptLogType( <i>logType</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Sets the type of information output by the current Python.print 
(Reference: KBEngine.LOG_TYPE_*)
</div>



<a name="urlopen"></a><p class="function_definition">
<span class="function_definition">def urlopen( <i>url, callback, postData, headers</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function is providing an external HTTP/HTTPS asynchronous request.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>url</i></span></td><td><span class="function_parameter_description">
A valid HTTP/HTTPS URL.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter with a callback object (for example, a function) that requests execution results. This callback takes five parameters: the HTTP request return code (eg: 200), 
the returned content, the returned HTTP protocol header, whether it succeeded, and the requested URL.
<br>
Example:<br>
def 
onHttpCallback(httpcode, data, headers, success, url):<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(httpcode, data, headers, success, url)  <br>
<br>
As the above example shows:
<br><p class="function_parameter_description"></p>httpcode:The parameter corresponds to the &quot;HTTP request return code&quot;, is an integer.
<p class="function_parameter_description"></p>data:The parameter is &ldquo; returned content & rdquo;, it is a string.
</p>
<p class="function_parameter_description">headers:The parameter is the HTTP protocol header returned by the server, such as:{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
<p class="function_parameter_description">success:Whether the execution is successful or not, when the request execution has an error, it is False, and the error information can be further judged by httpcode.
</p>
<p class="function_parameter_description"></p>url:Is the URL used by the request.
</p>
</td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>postData</i></span></td><td><span class="function_parameter_description">
Optional parameter, the default is GET mode request server. If you need POST mode, please provide the content that needs POST. The engine will automatically request the server using POST, is an bytes.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>headers</i></span></td><td><span class="function_parameter_description">
Optional parameter, HTTP header used when requesting, such as：{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
</span></td></tr>

</table>
</p>

        


<hr>
<h2>Callback functions documentation</h2>
</table>
</p>

<a name="onInit"></a><p class="function_definition">
<span class="function_definition">def onInit( <i>isReload</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called after all scripts have been initialized since 
the engine started.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isReload</i></span></td><td><span class="function_parameter_description">
bool, whether it was triggered after rewriting the loading script.
</span></td></tr>

</table>
</p>



<a name="onFinish"></a><p class="function_definition">
<span class="function_definition">def onFinish( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when the process shuts down.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

</table>
</p>


<hr>
<h2>Attributes documentation</h2>

<a name="bots"></a><p class="attribute_definition">
<span class="attribute_definition">bots</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
bots is a dictionary object that contains all client objects on the current 
process.<br>
</div>

<p>
<span class="attribute_type">Types:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td><a href="../Classes/PyClientApp.html">PyBots</a>
</td></tr>
</table>
</p>


<a name="component"></a><p class="attribute_definition">
<span class="attribute_definition">component</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This is the component that is running in the current scripting environment. 
(So far) Possible values are 'cellapp', 'baseapp', 'client', 'dbmgr', 'bots', 
and 'editor'.
</div>




<hr>
<p class="copyrightFooter">��Ȩ��KBEngine���С�</p>
</body>
</html>
